/*
 * Js Utils.
 * @Author: kerol
 * @Date: 2017-07-25
 */

/*
 * 定义一些常量
 */
var UNDEFINED = "undefined";


/*
 * cnzz统计
 */
var cnzz_id = '2255857003';
var params = parseParams();
var new_cnzz = params.new_cnzz;

// about cnzz
if (typeof new_cnzz != 'undefined' && new_cnzz != '') {
  cnzz_id = new_cnzz;
}
var _czc = _czc || [];
_czc.push(["_setAccount", cnzz_id]);
(function() {
  var cnzz_protocol1 = (("https:" == document.location.protocol) ? " https://" : " http://");
  var html1 = unescape("%3Cspan id='cnzz_stat_icon_" + cnzz_id + "'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol1 + "w.cnzz.com/q_stat.php%3Fid%3D" + cnzz_id + "%26l%3D3' type='text/javascript'%3E%3C/script%3E");
  document.write('<div style="display:none">' + html1 + '</div>');
})();

function trackEvent(category, action, label, value) {
  _czc.push(["_trackEvent", category, action, label, value]);
  //_hmt.push(['_trackEvent', category, action, label, value]);
}

// 百度统计
/* var _hmt = _hmt || [];
 (function() {
 var hm = document.createElement("script");
 hm.src = "//hm.baidu.com/hm.js?478c9b42c825ddf1b8f6ea20d576ac89";
 var s = document.getElementsByTagName("script")[0];
 s.parentNode.insertBefore(hm, s);
 })(); */

function parseParams(url) {
  if (url == undefined) {
    url = window.location.href;
  }
  var indexOfQ = url.indexOf('?');
  if (indexOfQ == -1) {
    return {};
  }
  var search = url.slice(indexOfQ + 1);
  var hashes = search.split('&');
  var params = {};
  for (var i = 0; i < hashes.length; i++) {
    var hash = hashes[i].split('=', 2);
    if (hash.length == 1) {
      params[hash[0]] = '';
    } else {
      params[hash[0]] = decodeURIComponent(hash[1]).replace(/\+/g, " ");
    }
  }
  return params;
}

/*
 * 获取url请求参数
 */
function getParam(key) {

  return params[key];

}

function getParam(key, defaultValue) {
  var value = params[key];
  console.log(value)
  return typeof(value) == UNDEFINED ? defaultValue : value;

}